{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 LucidaGrande;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww15680\viewh13200\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 I built an AFNI plugin with XCode.  It was frustrating but I got it to work.  XCode should make life easier for AFNI users in the Gold Lab.\
\
I tried to keep track of what I did, so that others can retrace my steps and maybe figure out where to start looking if something breaks in the future.\
\
The main idea was to extract build settings from the AFNI source code MakeFile and put them into the XCode project build settings.\
\
I don't understand all of the settings, the MakeFile is a bear, and I certainly did not copy every setting into XCode.  My thinking is that XCode should be smart enough to build correctly for OS X, and it should only take a few tweaks to get XCode to play nice with AFNI.  This approach seemed to work, but it means I might have missed something important that could crop up later.\
\
benjamin.heasly@gmail.com\
3 July 2009, Seattle, WA\
\
\
----1. Downloaded AFNI----\
I downloaded an AFNI binary from the project web site,\
	http://afni.nimh.nih.gov/afni/download/afni/releases/latest\
I unzipped it to\
	/Applications/AFNI.\
As per the installation instructions, I added the install folder to my path definition in ~/.bash_profile,\
	export PATH=/Applications/AFNI:/usr/local/bin:$PATH\
\
I downloaded the AFNI source code from the project site and unzipped it to\
	/Users/ben/Desktop/Labs/Gold/mri-cylk-project/afni_src\
\
\
----2. Downloaded openmotif----\
I downloaded the openmotif installer from the openmotif project web site,\
	http://www.ist-inc.com/DOWNLOADS/motif_download.html\
I ran the installer, which configured my machine and installed the library at\
	/usr/OpenMotif\
openmotif is the library AFNI uses to build its user interface.  afni.h needs some headers from this library.\
\
\
----3. XCode project----\
I made a new XCode project named "bung", using the "BSD Dynamic Library" template.\
\
I copied "plug_copy.c" from the AFNI source code folder to my XCode project, using the XCode right-click menu item "Add" -> "Existing Files..." . This singe file defines a basic AFNI plugin for copying a dataset.\
\
I tried building the project and got a large number of errors and warnings.\
\
\
----4. XCode build settings----\
I changed a bunch of build settings for the "bung" target in XCode:\
\
User-Defined settings:\
I defined some custom settings that locate files on my computer.\
AFNI_INSTALL is\
	/Applications/AFNI\
AFNI_SOURCE is \
	/Users/ben/Desktop/Labs/Gold/mri-cylk-project/afni_src\
MOTIF_LIBRARY is \
	/usr/OpenMotif\
\
Search Paths:\
Header Search Paths contains\
	$(AFNI_SOURCE)\
	$(MOTIF_LIBRARY)\
Library Search Paths contains\
	$(AFNI_INSTALL)\
	$(MOTIF_LIBRARY)\
For all path entries, I checked the recursive checkbox.\
\
Packaging:\
Executable Extension is \
	so\
Executable Prefix is \
	plug_\
\
Deployment:\
Deployment Target is\
	Mac OS X 10.3\
Installation Directory is\
	$(AFNI_SOURCE)\
\
Linking:\
I copied some linker flags from the "Makefile_macosx_g++" file that came with the AFNI source code.  I don't understand these, really.  The important one seems to be "-undefined suppress", which allows the library to build without the linker complaining that its symbols have no library to link against (I think that is the nature of a plugin).  I did not include the "-bundle" flag, which was also in the MakeFile, because XCode complained about it.\
Other Linker Flags contains\
	-dynamic \
	-L.\
	-L/usr/X11R6/lib \
	-Wl,-force_flat_namespace \
	-flat_namespace\
	-undefined suppress\
\
You can cut and paste this:\
-dynamic -L. -L/usr/X11R6/lib -Wl,-force_flat_namespace -flat_namespace -undefined suppress\
\
\
GCC 4.0 - Language:\
I copied one compiler flag from the same MakeFile.  This is a hint used in the AFNI source code for for platform-dependent compiling.  It is used by machdep.h, and possibly other headers included beneath afni.h.  It has the same effect as "#define DARWIN" and it means "hey, this is OS X".\
Other C Flags is\
	-DDARWIN\
\
The "GCC 4.0 - Language" section didn't appear in the target build settings until after I tried to build the target once.\
\
\
----5. Building the plugin----\
I built the bung target!  There were no errors and 109 warnings about things that are defined but unused.  I assume all or most of these warnings came from definitions in afni.h that are important for building AFNI itself, but don't matter for this little plugin.  It's dumb that we have to include this mammoth header just to compile a plugin.\
\
The build resulted in a library called\
	
\f1 plug_bung.so\
By default, AFNI looks for plugins in its home folder, so I copied my new plugin from the project build folder\
	bung/build/Debug/plug_bung.so\
into\
	/Applications/AFNI\
\
I launched AFNI and found an extra plugin for "Dataset Copy".  This is what I hoped to see, since my silly "bung" project was based on "plug_copy.c".  I tried copying a dataset using both plugins, and the behaviors seemed to be the same.  So I think the plugin I built in XCode was a good as the plugin that came with AFNI.}